package test;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

public class UdpClient {

	public static void main(String[] args) throws Exception{
		DatagramSocket sk=new DatagramSocket();
		String msg="I am John with UDP";
		InetAddress addr=InetAddress.getByName("127.0.0.1");
		
		DatagramPacket p=new DatagramPacket(msg.getBytes(), msg.length(), addr, 7777);
		sk.send(p);
		
		byte[] recBuf=new byte[1024];
		DatagramPacket recP=new DatagramPacket(recBuf, 1024);
		sk.receive(recP);
		
		String recmsg=new String(recP.getData(),0,recP.getLength());
		System.out.println(recmsg);
		
		
		sk.close();

	}

}
